﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace WindowsFormsApplication1
{
    class WriteCSP
    {
        public String m_cspnow;
        public CSPStructure m_cspstructure;

        String m_return = "\r\n";

        public WriteCSP() { }
        
        public void write() {

            foreach (String i in m_cspstructure.defines)
            {

                m_cspnow += i + ";" + m_return;
            }

            foreach (String i in m_cspstructure.vars) {

                m_cspnow += i + ";" + m_return;
 
            }

            m_cspnow += m_cspstructure.process + m_return;

            foreach (String i in m_cspstructure.events) {

                m_cspnow += i + ";" + m_return;
            }

            foreach (String i in m_cspstructure.asserts)
            {

                m_cspnow += i + ";" + m_return;
            }
        }

        public void writeFileAsString(String filename)
        {
            write();

            FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            try
            {
                sw.WriteLine(m_cspnow);
            }
            finally
            {
                if (sw != null) { sw.Close(); }
            }
        }

    }
}
